<?php

class Tour_IndexController extends Zend_Controller_Action
{

    public function init()
    {
        $this->params = $this->getRequest()->getParams();
        System_Template::using("userinfo","Default");
        $this->model = new Tour_Model_Tour();
        parent::init();
    }

    public function indexAction()
    {
        
    }
    public function orderlistAction()
    {
        $tableReservation = new System_Table_Reservation();
        $auth = Zend_Auth::getInstance();        
        $idCompany = $auth->getIdentity()->ID_COMPANY;
        $model = new Tour_Model_Reservation();
        $count = $model->countReservationList($idCompany);
        $lastPage = ceil($count/10);
        $pageCurrent = $this->params['page'];
        
        $search = array(
            "FROMDATE"=> common::convertToSystemDate($this->params['fromdate']),
            "TODATE"=> common::convertToSystemDate($this->params['todate']),
        );
        
        $data = $model->selectReservationList($idCompany,$pageCurrent,$search);
        $this->view->data = $data;
        $this->view->lastPage = $lastPage;
        $this->view->pageCurrent = $pageCurrent;
    }

    public function registerlistAction()
    {
        $auth = Zend_Auth::getInstance();
        $idCompany = $auth->getIdentity()->ID_COMPANY;
        $count = $this->model->countRegistryList($idCompany);
        $lastPage = ceil($count/10);
        $pageCurrent = $this->params['page'];
        $search = array(
            "FROMDATE"=> common::convertToSystemDate($this->params['fromdate']),
            "TODATE"=> common::convertToSystemDate($this->params['todate']),
        );
        $data = $this->model->selectRegistryList($idCompany,$pageCurrent,$search);
        $this->view->data = $data;
        $this->view->lastPage = $lastPage;
        $this->view->pageCurrent = $pageCurrent;
            
    }

    public function deleteAction()
    {
    
    }

    public function saveAction()
    {
        $auth = Zend_Auth::getInstance();
        $id_company = $auth->getIdentity()->ID_COMPANY;
        $tableTour = new System_Table_Tour();        
        $tableTourDescription = new System_Table_Tourdescription();
        
        $arrTour = array(
            "id_company" => $id_company,
            "code" => $this->params['MATOUR'] ,
            "number_of_day" => $this->params['SONGAY'],
            "number_of_night" => $this->params['SODEM'],
            "id_tour_category" =>$this->params['LOAITOUR'] ,
            "date_create" => date('Y-m-d'),
            "available" => (int)$this->params['KICHHOAT']
        );
        $idTour = $tableTour->insert($arrTour);        
        $uploader = new System_Upload();
        $uploadInfo = $uploader->upload();
        $arrTourDescription = array(
            "id_tour" => $idTour,
            "name" => $this->params['TEN'],
            "transport" => $this->params['PHUONGTHUCDICHUYEN'],
            "start_date" => common::convertToSystemDate($this->params['NGAYKHOIHANH']),
            "images" => 'upload/tours/'.$uploadInfo[0]['name'],
            "start_place" => $this->params['NOIKHOIHANH'],
            "journey" => $this->params['HANHTRINH'],
            "price_children" => $this->params['GIATREEM'],
            "limit_of_reservation" => $this->params['SOCHO'],
            "left_limit_of_reservation" => $this->params['SOCHO'],
            "price_adult" => $this->params['GIANGUOILON']
        );
        $tableTourDescription->insert($arrTourDescription);
        $this->_redirect("/tour/index/registerlist");
    }
    
    public function registerAction()
    {
        $table = new System_Table_Category();
        $tableCity = new System_Table_City();
        $this->view->listTourType = $table->fetchAll();
        $this->view->listCity = $tableCity->fetchAll();
    }
    public function introdutionAction()
    {
        
    
    }


}

